<?php if($user->access!=0){ ?>
<div id="page_admin">
<?php
if ($user->access != 2){
	$user->message->addError("Acces refused");
}else{
//liste des server
	$sql_query=mysql_query("Select id,name,address,pin,last_update from ".DATABASE_TABLE_SERVER." ORDER BY `name` ASC") or die(mysql_error());
?>
<div id="admin_action">
	<table>
		<caption>Admin action</caption>
			<tr>
				<td>
					<input type="button" value="Add server" onclick="affichage_popup('admin_add_server','370','200')"; />
					<input type="button" value="Add user" onclick="affichage_popup('admin_add_user','370','225')"; />
				</td>
			</tr>
			<tr>
				<td>
					<input type="button" value="Send Email" onclick="affichage_popup('admin_send_email','487','375')"; />
				</td>
			</tr>
	</table>
</div>

<div id="div_list_server">
	<form action= "index.php?page=admin" method="post">
		<table>
		<caption>List of servers</caption>
			<tr>
				<td class="title" colspan="3">Nom du partage</td>
				<td class="title">Adresse du serveur</td>
				<td class="title">Last update</td>
				<td class="title">Code pin du serveur</td>
			</tr>
<?php 
$i=0;
while ($query = mysql_fetch_array($sql_query) ){
$i=1;
?>
				<tr>
					<td><img alt="ref" src="./img/refresh-mini.png" onclick="refresh_serv('<?php print $query['name']; ?>',this);"/></td>
					<td><input type="checkbox" name="server_box[]" value="<?php echo $query['id'];?>"></td>
					<td><a onclick="affichage_popup('admin_server&idmodifserver=<?php print $query['id']; ?>','370','225')" href="" ><?php echo $query['name']; ?></a></td>
					<td><?php echo $query['address']; ?></td>
					<td><?php print date("d/m/y  G\hi\m",$query['last_update']);  ?></td>
					<td style="color:#FFFFFF" bgcolor="#FFFFFF" onmouseout="this.bgColor='#FFFFFF';" onmouseover="this.bgColor='#DADADA';"><?php echo $query['pin'];?></td>
				</tr>
<?php
}
if ($i==1){
?>
				<tr>
					<td colspan="6">
						<input type="hidden" name="hidden" value="server_remove" />
						<input type="submit" value="Supprimer" />
					</td>
				</tr>
<?php
}
?>
		</table>
	</form>
</div>
	



<div id="div_list_user">
		<form action= "index.php?page=admin" method="post">
		<table>
		<caption>List of users</caption>
		<tr>
			<td colspan="2" class="title">Login</td>
			<td class="title">Access</td>
			<td class="title">Last connection</td>
		</tr>
		<?php
			$sql_query=mysql_query("Select login,access,last_connect,id from ".DATABASE_TABLE_USER." ORDER BY `login` ASC") or die(mysql_error());
			$i=0;
			while ($query = mysql_fetch_array($sql_query) ){
				$i=1;
		?>
		<tr>
			<td><input type="checkbox" name="user_box[]" value="<?php print $query['id']; ?>"></td>
			<td><a href="" onclick="affichage_popup('admin_user&idmodifuser=<?php print $query['id']; ?>','450','550')" ><?php print $query['login']; ?></a></td>
			<td><?php if( $query['access'] == 2)print "admin";elseif($query['access'] == 1)print "user";elseif($query['access'] == 0)print "blocked";else print "error";  ?></td>
			<td><?php echo  date( "G\hi d/m/y",$query['last_connect']); ?></td>
		</tr>
		<?php } ?>
		<input type="hidden" name="hidden" value="user_remove" />
		<?php 
			if ($i==1){
		?>				
				<tr>
					<td colspan="4">
						<input type="submit" value="Supprimer" />
					</td>
				</tr>
			<?php } ?>
		</table>
		</form>
</div>
<div id="div_log">
		<table>
		<caption>Log <a href="" onclick="location.reload;">refresh</a></caption>
		<tr>
		<td class="title">Action</td><td class="title">User</td><td class="title">date</td><td class="title">server</td>
		</tr>
		<?php 
		$sql_query = mysql_query("Select action,server,user,date from ".DATABASE_TABLE_LOG." ORDER BY `date` DESC LIMIT 0 , 15");
		while ($query = mysql_fetch_array($sql_query)  ){
		?>
		<tr  bgcolor="#ffffff" onmouseout="this.bgColor='#FFFFFF';" onmouseover="this.bgColor='#DADADA';" >
		<td class="log_action"><?php print $query['action']; ?></td><td class = "log_user"><?php print $query['user']; ?></td><td class ="log_date"><?php print date( "d/m/y à G\h i\m",$query['date']) ; ?></td><td class="log_server"><?php print $query['server']; ?></td>
		</tr>
		<?php
		}
		?>
		</table>
</div>
<?php } ?>
</div>
<?php } ?>